<!--
 * @Descripttion: 
 * @Author: dedeye
 * @Date: 2020-02-26 20:04:00
 * @LastEditors: dedeye
 * @LastEditTime: 2020-02-27 17:35:28
 -->
 <!DOCTYPE html>
 <html>
 <head>
     <meta charset="utf-8">
     <title>layui</title>
     <meta name="renderer" content="webkit">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
     <link rel="stylesheet" href="__ADMIN__/lib/layui-v2.5.5/css/layui.css" media="all">
     <link rel="stylesheet" href="__ADMIN__/css/public.css" media="all">
     <style>
         body {
             background-color: #ffffff;
         }
     </style>
 </head>
 <body>
 <div class="layui-form layuimini-form" lay-filter="editForm">
     {:token('mykey')}
     <div class="layui-form-item">
         <label class="layui-form-label required">名称</label>
         <div class="layui-input-block">
            <input type="hidden" name="id">
             <input type="text" name="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" value="" class="layui-input">
         </div>
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label required">说明</label>
         <div class="layui-input-block">
                <textarea name="description" placeholder="请输入说明" class="layui-textarea"></textarea>
         </div>
     </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">hash值</label>
        <div class="layui-input-block">
            <input type="text" name="hash" lay-verify="required" lay-reqtext="hash值不能为空" placeholder="请输入hash值" value="" class="layui-input">
        </div>
    </div>
     <div class="layui-form-item">
         <label class="layui-form-label">状态</label>
         <div class="layui-input-block">
             <input type="checkbox" name="status" lay-skin="switch" lay-text="正常|禁用" checked>
         </div>
     </div>
     <div class="layui-form-item">
         <div class="layui-input-block">
             <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
         </div>
     </div>
 </div>
 </div>
 <script src="__ADMIN__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
 <script>
     layui.use(['form'], function () {
         var form = layui.form,
             layer = layui.layer,
             $ = layui.jquery;

        var collectionId = parent.$('#hideCollectionId').val();
        var addData = layer.load();
        $.ajax({
            url: '/admin/group/read/' + collectionId,
            success: function (res) {
                layer.close(addData);
                if(res.code < 0) {
                    layer.msg(res.msg, {
                        icon: 2,
                        time: 1000,
                        shade: 0.1
                    }, function () {
                        closeThis()
                    });
                    return false;
                }
                form.val("editForm", {
                    "id": res.data.id,
                    "name": res.data.name,
                    "description": res.data.description,
                    "hash": res.data.hash,
                    "status": res.data.status == 1 ? true : false
                });
            }
        })
         //监听提交
         form.on('submit(saveBtn)', function (data) {
             const param = data.field;
             if(param.status && param.status == 'on') {
                 param.status = 1;
             } else {
                 param.status = 0;
             }
             $.ajax({
                 url: '/admin/group/edit',
                 data: param,
                 method: 'post',
                 success: function (res) {
                     if(res.code < 0) {
                         layer.msg(res.msg, {icon: 5,time: 500,shade: 0.1});
                         return false;
                     }
                     layer.msg(res.msg, {
                         icon: 1,
                         time: 500,
                         shade: 0.1
                     }, function () {
                         closeThis(true)
                     });
                 }
             })
             return false;
         });
 
         function closeThis(re = false)
         {
             var iframeIndex = parent.layer.getFrameIndex(window.name);
             if(re)
                 parent.$('#isReload').val('yes');
             parent.layer.close(iframeIndex);
         }
     });
 </script>
 </body>
 </html>